<template>
  <el-dialog
    title="选择回退的节点"
    width="800px"
    :before-close="handleClose"
    :visible="visible"
  >
    <el-radio-group v-model="chioseKey">
      <el-radio v-for="item in nodes" :key="item.key" :label="item.key">
        <span>{{ item.Name + '[' +FlowAuditType[item.AuditType].text+ ']' }}</span>
        <span>{{ item.EmpName }}</span>
      </el-radio>
    </el-radio-group>
    <div slot="footer" style="text-align: center">
      <el-button type="primary" @click="submit">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { FlowAuditType } from '@/flow/config/flowConfig'
export default {
  components: {
  },
  props: {
    backNode: {
      type: Array,
      default: null
    },
    visible: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      FlowAuditType,
      chioseKey: null,
      nodes: []
    }
  },
  computed: {
  },
  watch: {
    visible: {
      handler(val) {
        if (val) {
          this.reset()
        }
      },
      immediate: true
    }
  },
  mounted() {},
  methods: {
    handleClose() {
      this.$emit('update:visible', false)
    },
    reset() {
      this.nodes = this.backNode.map(c => {
        return {
          BatchNo: c.BatchNo,
          Id: c.Id,
          key: c.Id + '_' + c.BatchNo,
          Name: c.Name,
          AuditType: c.AuditType,
          EmpId: c.EmpId,
          EmpName: c.EmpName.join(',')
        }
      })
      this.chioseKey = this.nodes.length === 1 ? this.nodes[0].key : null
    },
    submit() {
      if (this.chioseKey == null) {
        this.$message({
          type: 'error',
          message: '请选择一个回退节点!'
        })
        return
      }
      const item = this.nodes.find(c => c.key === this.chioseKey)
      this.$emit('update:visible', false)
      this.$emit('save', item)
    }
  }
}
</script>
<style scoped>
.el-radio {
    display:inline-flex;
    width: 100%;
    padding: 5px;
}
.el-radio span {
     display:inline-flex;
    width: 200px;
}
</style>
